package com.atguigu.day22.tcpsocket.s4;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;
/*
客户端 向服务端发送一个信息  服务端对数据反转 再反馈
A   ABCD                 ABCD
    DCBA
B  1234                  1234
   4321
 */
public class Client22 {
    public static void main(String[] args) throws IOException {
        System.out.println("-----------Client2--------------");
        //1.创建客户端对象
        Socket socket = new Socket("127.0.0.1",9999);
        //2.获取字节输出流
        OutputStream os = socket.getOutputStream();
        //3.转为打印流
        PrintStream ps = new PrintStream(os);
        //4.写出数据
        ps.println("你爱Java吗 ? ");
        //5.获取字节输入流
        InputStream is = socket.getInputStream();
        //6.转为Scanner
        Scanner sc = new Scanner(is);
        //7.接收数据并展示
        String s = sc.nextLine();
        System.out.println("服务端反馈的信息是 = " + s);
        //8.关闭资源
        sc.close();
        ps.close();
        socket.close();
    }
}
